package com.ybwh.springboot2.sharding5.ext.kengen;


import com.xfvape.uid.UidGenerator;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;

import java.util.Properties;

/**
 * <p>
 *  百度UidGenerator
 * </p>
 *
 * @author fanbeibei
 * @version 1.0.0
 * @date 2023/4/12 14:51
 */
public class BaiduUid implements KeyGenerateAlgorithm {


    private Properties props;

    private UidGenerator uidGenerator;


    @Lazy
    @Autowired
    public BaiduUid(UidGenerator uidGenerator) {
        this.uidGenerator = uidGenerator;
    }

    @Override
    public void init(final Properties props) {
        this.props = props;
    }

    @Override
    public Comparable<?> generateKey() {


        return uidGenerator.getUID();
    }

    @Override
    public String getType() {
        return "uidGenerator";
    }

    @Override
    public boolean isDefault() {
        return true;
    }



}
